package com.example.mychatgpt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mychatgpt.entity.records;
import com.example.mychatgpt.entity.records_item;
import com.example.mychatgpt.entity.user;
import com.example.mychatgpt.mapper.recordsItemMapper;
import com.example.mychatgpt.mapper.recordsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
public class recordsService {
    @Autowired
    recordsMapper recordsmapper;
    @Autowired
    recordsItemMapper recordsitemmapper;
    public List<Map<String, Object>> getRecordsByAccount(String account){
        return recordsmapper.selectMaps(new QueryWrapper<records>().eq("user_account",account));
    }
    public List<Map<String, Object>> getRecordsItemByRecordsId(int recordsId){
        return recordsitemmapper.selectMaps(new QueryWrapper<records_item>().eq("records_id",recordsId));
    }
    public List<Map<String, Object>> getRecordsById(int recordsId){
        return recordsmapper.selectMaps(new QueryWrapper<records>().eq("id",recordsId));
    }
    public records_item insertRecordsItem( String role,String content,int recordsId){

        try{
            records_item toInsert=new records_item();
            toInsert.setContent(content);
            toInsert.setRole(role);
            toInsert.setRecordsId(recordsId);
            recordsitemmapper.insert(toInsert);
            return toInsert;
        }catch (Exception e){
            System.out.println(e.toString());
            return null;
        }

    }
    public records addRecords(String title, String account){
        records toAdd=new records();
        toAdd.setUserAccount(account);
        toAdd.setTitle(title);
        recordsmapper.insert(toAdd);
        return toAdd;
    }
}
